<?php

namespace App\model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class dataCore extends Model
{
    //
    public function __construct(){
    }

    public function search($table, $where = ''){
        $resoult = DB::table($table)->where($where)->get()->toArray();
        return $resoult;
    }

    public function searchInMode($table, $where = '', $model){
        if ($model == 'title') {
            $resoult['id'] = DB::table($table)->pluck('id');
            $resoult['title'] = DB::table($table)->pluck('title');
            $resoult['status'] = DB::table($table)->pluck('status');
            for ($i = 0; $i < count($resoult['title']); $i++) {
                $returnResoult[$i]['id'] = $resoult['id'][$i];
                $returnResoult[$i]['title'] = $resoult['title'][$i];
                $returnResoult[$i]['status'] = $resoult['status'][$i];
            }
            $returnResoult = isset($returnResoult) ? $returnResoult : NULL;
        }else{
            $returnResoult = DB::table($table)->where($where)->get();
        }
        
        return $returnResoult;
    }

    public function pushTheData($table, $data){
    	$resoult = DB::table($table)->insert($data) ? 1 : 0;
    	return $resoult;
    }

}
